package site.jlopen.kuscia.entity;

import site.jlopen.kuscia.properties.KusciaAPIProperties;

/**
 * @ClassName: GrpcApiInfo
 * @Description: 访问grpc所需参数
 * @author ChenJiaLu
 * @date 2024年7月14日 上午1:35:35
 *
 */
public abstract class GrpcApiInfo {
	
	public final static String NOTLS = "notls";
	
	public final static String TLS = "tls";
	
	public final static String MTLS = "mtls";

	public abstract String getAddress();

	public abstract String getTokenFile();

	public abstract String getProtocol();

	public abstract GrpcApiInfoTls getTls();

	public abstract class GrpcApiInfoTls {

		public abstract String getCertFile();

		public abstract String getKeyFile();

		public abstract String getCaFile();
	}

	public KusciaAPIProperties convert(GrpcApiInfo apiInfo) {
		KusciaAPIProperties propertie = new KusciaAPIProperties();
		propertie.setAddress(apiInfo.getAddress());
		propertie.setProtocol(apiInfo.getProtocol());
		propertie.setTokenFile(apiInfo.getTokenFile());
		GrpcApiInfoTls tls = apiInfo.getTls();
		if (null != tls) {
			propertie.getTls().setCaFile(tls.getCaFile());
			propertie.getTls().setCertFile(tls.getCertFile());
			propertie.getTls().setKeyFile(tls.getKeyFile());
		}
		return propertie;
	}
}
